package com.future.mayi.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.future.baselib.utils.CommonUtils;
import com.future.baselib.utils.DataCleanManager;
import com.future.mayi.R;
import com.future.mayi.dialog.ClearCacheDialog;
import com.future.mayi.model.interfaces.DialogEnterListener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseTitleActivity implements DialogEnterListener {
    @BindView(R.id.tv_cache)
    TextView tvCache;
    @BindView(R.id.tv_vision)
    TextView tvVision;

    @Override
    protected void initTopBar() {
        initBack();
        getTitleText().setText("设置");
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_setting);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initDates() {
        try {
            tvCache.setText(DataCleanManager.getTotalCacheSize(getApplicationContext()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        tvVision.setText("版本号：" + CommonUtils.getAppVersion(mContext));
    }

    @Override
    protected void initListener() {

    }

    private ClearCacheDialog dialog;

    @OnClick({R.id.tv_change_phone, R.id.tv_psw, R.id.tv_agreement, R.id.ll_cache})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_change_phone:
                startActivity(new Intent(this, ChangePhoneActivity.class));
                break;
            case R.id.tv_psw:
                startActivity(new Intent(this, SettingPayPasswordActivity.class));
                break;
            case R.id.tv_agreement:
                startActivity(new Intent(this, AgreementActivity.class));
                break;
            case R.id.ll_cache:
                if (dialog == null) {
                    dialog = new ClearCacheDialog(this);
                    dialog.setListener(this);
                }
                dialog.show();
                break;
        }
    }

    @Override
    public void cancel(Object tag) {

    }

    @Override
    public void enter(Object tag) {
        DataCleanManager.clearAllCache(SettingActivity.this.getApplicationContext());
        try {
            tvCache.setText(DataCleanManager.getTotalCacheSize(SettingActivity.this.getApplicationContext()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
